package conf

import (
	"wire/internal/model"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"gorm.io/gorm/schema"
)

func NewGorm() *gorm.DB {
	url := "root:root@tcp(localhost:13316)/wire?charset=utf8mb4&parseTime=True&loc=Local"
	config := &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
	}
	Db, err := gorm.Open(mysql.Open(url), config)
	if err != nil {
		panic(err)
	}
	err = model.InitTables(Db)
	if err != nil {
		panic(err)
	}
	return Db
}
